package com.mypaper.main;

import com.mypaper.schedule.*;
import com.mypaper.dag.*;

public class ClassTest
{
	public static void main(String args[]){
		int better = 0,better2 = 0;
		float betterValue = 0.0f;
		float worseValue = 0.0f;
		int soso = 0,soso2 = 0;
		int worse = 0,worse2 = 0;
		int teCount = 1;
		String re = "[HTR,HEFT]--";
		String reWorse = "[HTR,HEFT]--";
		for(int te = 0; te < teCount; te++)
		{
	
//		short procNum=5,vertexNum=14;
//		int[][] commDAG={{0,1,1,1,1,0,0,0,0,0,0,0,0,0},//1
//				{0,0,0,0,0,1,0,0,0,0,0,0,0,0},//2
//				{0,0,0,0,0,0,1,0,0,0,0,0,0,0},//3
//				{0,0,0,0,0,0,0,1,0,0,0,0,0,0},//4
//				{0,0,0,0,0,0,0,0,1,0,0,0,0,0,0},//5
//				{0,0,0,0,0,0,1,1,1,0,0,0,0,0},//6
//				{0,0,0,0,0,0,0,0,0,1,0,0,0,0},//7
//				{0,0,0,0,0,0,0,0,0,0,1,0,0,0},//8
//				{0,0,0,0,0,0,0,0,0,0,0,1,0,0},//9
//				{0,0,0,0,0,0,0,0,0,0,1,1,0,0},//10
//				{0,0,0,0,0,0,0,0,0,0,0,0,1,0},//11
//				{0,0,0,0,0,0,0,0,0,0,0,0,0,1},//12
//				{0,0,0,0,0,0,0,0,0,0,0,0,0,1},//13
//				{0,0,0,0,0,0,0,0,0,0,0,0,0,0},//14
//				};
//		float CCR=1f;
//		//
//		Benchmarks ben=new Benchmarks(vertexNum,procNum,commDAG,CCR);
//		float[][] vertexWeight=ben.comp;
//		float[][] edgeWeight=ben.comm;
//			dag.DAGFileReader();
//			DAGGenerator dag = new DAGGenerator(4,12,(float)3,(float) 1);
//			DAGGenerator dag = new DAGGenerator();			
		DAGGenerator dag = new DAGGenerator(4,12,(float)0.2,(float)1);
		//dag.DAGFileReader();
		int vertexNum = dag.TASKNUM;
		int procNum = dag.PROCNUM;
		float[][] vertexWeight = dag.comp;
		float[][] edgeWeight = dag.comm;
		dag.DAGFileWriter();
		for(int i = 0; i < vertexNum; i++)
			for(int j = 0; j < vertexNum; j++)
			{
				if(edgeWeight[i][j] != 0)System.out.println(i +"-->"+j);
			}
			
			
		RefactorDAG refDAG = new RefactorDAG(vertexNum, procNum, vertexWeight, edgeWeight); 
		refDAG.HTRCP();
		
		HTRSchedule htrSchedule = new HTRSchedule(refDAG);
		try
		{
			htrSchedule.HTR_Algrithm(refDAG);
		} catch (Exception e)
		{
			dag.DAGFileWriter();
			e.printStackTrace();
			throw e;
		}
		float makespan = htrSchedule.makespan();
		System.out.println("The makespan of HTR is:" + makespan);
		htrSchedule.scheduleResults.print();
		
		DAG dagHEFT=new DAG(vertexNum,procNum,vertexWeight,edgeWeight);
		dagHEFT.calcBLPrior();
		HEFTSchedule heftSchedule=new HEFTSchedule(dagHEFT);//初始化
		heftSchedule.HEFT_Algorithm(dagHEFT);//调度
		float makespanHEFT=heftSchedule.makespan();//求makespan
		System.out.println("The makespan of HEFT is " + makespanHEFT);
		heftSchedule.scheduleResults.print();
		
		DAG dagCPOP = new DAG(vertexNum,procNum,vertexWeight,edgeWeight);
		dagCPOP.priorCPOP();
		CPOPSchedule cpopSchedule = new CPOPSchedule(dagCPOP);
		cpopSchedule.CPOP_Algorithm(dagCPOP);
		float makespanCPOP = cpopSchedule.makespan();
		System.out.println("The makespan of CPOP is " + makespanCPOP);
		
		if(makespan < makespanHEFT)
		{
			better++;
			betterValue += makespanHEFT - makespan;
			re += "[" + makespan + "," + makespanHEFT + "]=" + (makespanHEFT - makespan) + ", ";
			dag.DAGFileWriter();
		}
		else if(makespan > makespanHEFT)
			{
			  worse++;
			  worseValue += makespan - makespanHEFT;
			  reWorse += "[" + makespan + "," + makespanHEFT + "]=" + (makespan - makespanHEFT) + ", ";
			}
		else soso++;
		
		if(makespan < makespanCPOP)better2++;
		else if(makespan == makespanCPOP)soso2++;
		else worse2++;
		
	    }
		
		System.out.println("My schedule performs better than HEFT's count:" + better);
		System.out.println("My schedule performs soso on HEFT's count:" + soso);
		System.out.println("My schedule performs worse than HEFT's count:" + worse);
		System.out.println("-----------------------------------------------------");
		System.out.println("My schedule performs better than CPOP's count:" + better2);
		System.out.println("My schedule performs soso on CPOP's count:" + soso2);
		System.out.println("My schedule performs worse than CPOP's count:" + worse2);
		System.out.println("HTR's betterValue = " + betterValue);
		System.out.println("HEFT's betterValue = " + worseValue);
		System.out.println("具体好的程度：");
		System.out.println(re);
		System.out.println("具体差的程度：");
		System.out.println(reWorse);
		
	}
}
